using System;
using System.Data;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Globalization;
using System.Windows.Forms;
using C1.Win.C1TrueDBGrid;
using PCSComUtils.Admin.DS;
using PCSComUtils.Common;
using PCSComUtils.Admin.BO;
using PCSComUtils.Framework.TableFrame.BO;
using PCSComUtils.PCSExc;
using PCSUtils.Log;
using PCSUtils.Utils;

namespace PCSUtils.Admin
{
	/// <summary>
	/// Summary description for RightByRecord.
	/// </summary>
	public class RightByRecord : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button btnClose;
		private System.Windows.Forms.Button btnHelp;
		private System.Windows.Forms.Button btnSave;
		private System.Windows.Forms.Label lblRole;
		private System.Windows.Forms.ComboBox cboRoles;
		private System.Windows.Forms.Label lblType;
		private System.Windows.Forms.ComboBox cboType;
		private C1.Win.C1TrueDBGrid.C1TrueDBGrid dgrdData;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
		const string THIS = "PCSUtils.Admin.RightByRecord";
		private const string SELECT = "Select";
		private const string FORMAT_TEXT = "FormatText Event";
		
		string strLangName = CultureInfo.CurrentUICulture.Name;
		string strText = string.Empty;

		string strPKColumnName, strFKColumnName, strPKTable_Name, strSecurityTableName;
		DataSet dstData = new DataSet();
		DataSet dstRole = new DataSet();
		DataSet dstTypes = new DataSet();
		DataSet dstSecurityTable = new DataSet();
		private bool blnHasError = false;
		private System.Windows.Forms.CheckBox chkSelectAll;
		const int INVISIBLE_COLUMN_WIDTH = 1;
		public RightByRecord()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
																				{
																								System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(RightByRecord));
																								this.btnClose = new System.Windows.Forms.Button();
																								this.btnHelp = new System.Windows.Forms.Button();
																								this.btnSave = new System.Windows.Forms.Button();
																								this.lblRole = new System.Windows.Forms.Label();
																								this.cboRoles = new System.Windows.Forms.ComboBox();
																								this.lblType = new System.Windows.Forms.Label();
																								this.cboType = new System.Windows.Forms.ComboBox();
																								this.dgrdData = new C1.Win.C1TrueDBGrid.C1TrueDBGrid();
																								this.chkSelectAll = new System.Windows.Forms.CheckBox();
																								((System.ComponentModel.ISupportInitialize)(this.dgrdData)).BeginInit();
																								this.SuspendLayout();
																								// 
																								// btnClose
																								// 
																								this.btnClose.AccessibleDescription = resources.GetString("btnClose.AccessibleDescription");
																								this.btnClose.AccessibleName = resources.GetString("btnClose.AccessibleName");
																								this.btnClose.Anchor = ((System.Windows.Forms.AnchorStyles)(resources.GetObject("btnClose.Anchor")));
																								this.btnClose.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("btnClose.BackgroundImage")));
																								this.btnClose.DialogResult = System.Windows.Forms.DialogResult.Cancel;
																								this.btnClose.Dock = ((System.Windows.Forms.DockStyle)(resources.GetObject("btnClose.Dock")));
																								this.btnClose.Enabled = ((bool)(resources.GetObject("btnClose.Enabled")));
																								this.btnClose.FlatStyle = ((System.Windows.Forms.FlatStyle)(resources.GetObject("btnClose.FlatStyle")));
																								this.btnClose.Font = ((System.Drawing.Font)(resources.GetObject("btnClose.Font")));
																								this.btnClose.Image = ((System.Drawing.Image)(resources.GetObject("btnClose.Image")));
																								this.btnClose.ImageAlign = ((System.Drawing.ContentAlignment)(resources.GetObject("btnClose.ImageAlign")));
																								this.btnClose.ImageIndex = ((int)(resources.GetObject("btnClose.ImageIndex")));
																								this.btnClose.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("btnClose.ImeMode")));
																								this.btnClose.Location = ((System.Drawing.Point)(resources.GetObject("btnClose.Location")));
																								this.btnClose.Name = "btnClose";
																								this.btnClose.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("btnClose.RightToLeft")));
																								this.btnClose.Size = ((System.Drawing.Size)(resources.GetObject("btnClose.Size")));
																								this.btnClose.TabIndex = ((int)(resources.GetObject("btnClose.TabIndex")));
																								this.btnClose.Text = resources.GetString("btnClose.Text");
																								this.btnClose.TextAlign = ((System.Drawing.ContentAlignment)(resources.GetObject("btnClose.TextAlign")));
																								this.btnClose.Visible = ((bool)(resources.GetObject("btnClose.Visible")));
																								this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
																								// 
																								// btnHelp
																								// 
																								this.btnHelp.AccessibleDescription = resources.GetString("btnHelp.AccessibleDescription");
																								this.btnHelp.AccessibleName = resources.GetString("btnHelp.AccessibleName");
																								this.btnHelp.Anchor = ((System.Windows.Forms.AnchorStyles)(resources.GetObject("btnHelp.Anchor")));
																								this.btnHelp.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("btnHelp.BackgroundImage")));
																								this.btnHelp.Dock = ((System.Windows.Forms.DockStyle)(resources.GetObject("btnHelp.Dock")));
																								this.btnHelp.Enabled = ((bool)(resources.GetObject("btnHelp.Enabled")));
																								this.btnHelp.FlatStyle = ((System.Windows.Forms.FlatStyle)(resources.GetObject("btnHelp.FlatStyle")));
																								this.btnHelp.Font = ((System.Drawing.Font)(resources.GetObject("btnHelp.Font")));
																								this.btnHelp.Image = ((System.Drawing.Image)(resources.GetObject("btnHelp.Image")));
																								this.btnHelp.ImageAlign = ((System.Drawing.ContentAlignment)(resources.GetObject("btnHelp.ImageAlign")));
																								this.btnHelp.ImageIndex = ((int)(resources.GetObject("btnHelp.ImageIndex")));
																								this.btnHelp.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("btnHelp.ImeMode")));
																								this.btnHelp.Location = ((System.Drawing.Point)(resources.GetObject("btnHelp.Location")));
																								this.btnHelp.Name = "btnHelp";
																								this.btnHelp.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("btnHelp.RightToLeft")));
																								this.btnHelp.Size = ((System.Drawing.Size)(resources.GetObject("btnHelp.Size")));
																								this.btnHelp.TabIndex = ((int)(resources.GetObject("btnHelp.TabIndex")));
																								this.btnHelp.Text = resources.GetString("btnHelp.Text");
																								this.btnHelp.TextAlign = ((System.Drawing.ContentAlignment)(resources.GetObject("btnHelp.TextAlign")));
																								this.btnHelp.Visible = ((bool)(resources.GetObject("btnHelp.Visible")));
																								// 
																								// btnSave
																								// 
																								this.btnSave.AccessibleDescription = resources.GetString("btnSave.AccessibleDescription");
																								this.btnSave.AccessibleName = resources.GetString("btnSave.AccessibleName");
																								this.btnSave.Anchor = ((System.Windows.Forms.AnchorStyles)(resources.GetObject("btnSave.Anchor")));
																								this.btnSave.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("btnSave.BackgroundImage")));
																								this.btnSave.Dock = ((System.Windows.Forms.DockStyle)(resources.GetObject("btnSave.Dock")));
																								this.btnSave.Enabled = ((bool)(resources.GetObject("btnSave.Enabled")));
																								this.btnSave.FlatStyle = ((System.Windows.Forms.FlatStyle)(resources.GetObject("btnSave.FlatStyle")));
																								this.btnSave.Font = ((System.Drawing.Font)(resources.GetObject("btnSave.Font")));
																								this.btnSave.Image = ((System.Drawing.Image)(resources.GetObject("btnSave.Image")));
																								this.btnSave.ImageAlign = ((System.Drawing.ContentAlignment)(resources.GetObject("btnSave.ImageAlign")));
																								this.btnSave.ImageIndex = ((int)(resources.GetObject("btnSave.ImageIndex")));
																								this.btnSave.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("btnSave.ImeMode")));
																								this.btnSave.Location = ((System.Drawing.Point)(resources.GetObject("btnSave.Location")));
																								this.btnSave.Name = "btnSave";
																								this.btnSave.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("btnSave.RightToLeft")));
																								this.btnSave.Size = ((System.Drawing.Size)(resources.GetObject("btnSave.Size")));
																								this.btnSave.TabIndex = ((int)(resources.GetObject("btnSave.TabIndex")));
																								this.btnSave.Text = resources.GetString("btnSave.Text");
																								this.btnSave.TextAlign = ((System.Drawing.ContentAlignment)(resources.GetObject("btnSave.TextAlign")));
																								this.btnSave.Visible = ((bool)(resources.GetObject("btnSave.Visible")));
																								this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
																								// 
																								// lblRole
																								// 
																								this.lblRole.AccessibleDescription = resources.GetString("lblRole.AccessibleDescription");
																								this.lblRole.AccessibleName = resources.GetString("lblRole.AccessibleName");
																								this.lblRole.Anchor = ((System.Windows.Forms.AnchorStyles)(resources.GetObject("lblRole.Anchor")));
																								this.lblRole.AutoSize = ((bool)(resources.GetObject("lblRole.AutoSize")));
																								this.lblRole.Dock = ((System.Windows.Forms.DockStyle)(resources.GetObject("lblRole.Dock")));
																								this.lblRole.Enabled = ((bool)(resources.GetObject("lblRole.Enabled")));
																								this.lblRole.Font = ((System.Drawing.Font)(resources.GetObject("lblRole.Font")));
																								this.lblRole.ForeColor = System.Drawing.Color.Maroon;
																								this.lblRole.Image = ((System.Drawing.Image)(resources.GetObject("lblRole.Image")));
																								this.lblRole.ImageAlign = ((System.Drawing.ContentAlignment)(resources.GetObject("lblRole.ImageAlign")));
																								this.lblRole.ImageIndex = ((int)(resources.GetObject("lblRole.ImageIndex")));
																								this.lblRole.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("lblRole.ImeMode")));
																								this.lblRole.Location = ((System.Drawing.Point)(resources.GetObject("lblRole.Location")));
																								this.lblRole.Name = "lblRole";
																								this.lblRole.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("lblRole.RightToLeft")));
																								this.lblRole.Size = ((System.Drawing.Size)(resources.GetObject("lblRole.Size")));
																								this.lblRole.TabIndex = ((int)(resources.GetObject("lblRole.TabIndex")));
																								this.lblRole.Text = resources.GetString("lblRole.Text");
																								this.lblRole.TextAlign = ((System.Drawing.ContentAlignment)(resources.GetObject("lblRole.TextAlign")));
																								this.lblRole.Visible = ((bool)(resources.GetObject("lblRole.Visible")));
																								// 
																								// cboRoles
																								// 
																								this.cboRoles.AccessibleDescription = resources.GetString("cboRoles.AccessibleDescription");
																								this.cboRoles.AccessibleName = resources.GetString("cboRoles.AccessibleName");
																								this.cboRoles.Anchor = ((System.Windows.Forms.AnchorStyles)(resources.GetObject("cboRoles.Anchor")));
																								this.cboRoles.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("cboRoles.BackgroundImage")));
																								this.cboRoles.Dock = ((System.Windows.Forms.DockStyle)(resources.GetObject("cboRoles.Dock")));
																								this.cboRoles.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
																								this.cboRoles.Enabled = ((bool)(resources.GetObject("cboRoles.Enabled")));
																								this.cboRoles.Font = ((System.Drawing.Font)(resources.GetObject("cboRoles.Font")));
																								this.cboRoles.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("cboRoles.ImeMode")));
																								this.cboRoles.IntegralHeight = ((bool)(resources.GetObject("cboRoles.IntegralHeight")));
																								this.cboRoles.ItemHeight = ((int)(resources.GetObject("cboRoles.ItemHeight")));
																								this.cboRoles.Location = ((System.Drawing.Point)(resources.GetObject("cboRoles.Location")));
																								this.cboRoles.MaxDropDownItems = ((int)(resources.GetObject("cboRoles.MaxDropDownItems")));
																								this.cboRoles.MaxLength = ((int)(resources.GetObject("cboRoles.MaxLength")));
																								this.cboRoles.Name = "cboRoles";
																								this.cboRoles.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("cboRoles.RightToLeft")));
																								this.cboRoles.Size = ((System.Drawing.Size)(resources.GetObject("cboRoles.Size")));
																								this.cboRoles.TabIndex = ((int)(resources.GetObject("cboRoles.TabIndex")));
																								this.cboRoles.Text = resources.GetString("cboRoles.Text");
																								this.cboRoles.Visible = ((bool)(resources.GetObject("cboRoles.Visible")));
																								this.cboRoles.SelectedIndexChanged += new System.EventHandler(this.cboType_SelectedIndexChanged);
																								// 
																								// lblType
																								// 
																								this.lblType.AccessibleDescription = resources.GetString("lblType.AccessibleDescription");
																								this.lblType.AccessibleName = resources.GetString("lblType.AccessibleName");
																								this.lblType.Anchor = ((System.Windows.Forms.AnchorStyles)(resources.GetObject("lblType.Anchor")));
																								this.lblType.AutoSize = ((bool)(resources.GetObject("lblType.AutoSize")));
																								this.lblType.Dock = ((System.Windows.Forms.DockStyle)(resources.GetObject("lblType.Dock")));
																								this.lblType.Enabled = ((bool)(resources.GetObject("lblType.Enabled")));
																								this.lblType.Font = ((System.Drawing.Font)(resources.GetObject("lblType.Font")));
																								this.lblType.ForeColor = System.Drawing.Color.Maroon;
																								this.lblType.Image = ((System.Drawing.Image)(resources.GetObject("lblType.Image")));
																								this.lblType.ImageAlign = ((System.Drawing.ContentAlignment)(resources.GetObject("lblType.ImageAlign")));
																								this.lblType.ImageIndex = ((int)(resources.GetObject("lblType.ImageIndex")));
																								this.lblType.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("lblType.ImeMode")));
																								this.lblType.Location = ((System.Drawing.Point)(resources.GetObject("lblType.Location")));
																								this.lblType.Name = "lblType";
																								this.lblType.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("lblType.RightToLeft")));
																								this.lblType.Size = ((System.Drawing.Size)(resources.GetObject("lblType.Size")));
																								this.lblType.TabIndex = ((int)(resources.GetObject("lblType.TabIndex")));
																								this.lblType.Text = resources.GetString("lblType.Text");
																								this.lblType.TextAlign = ((System.Drawing.ContentAlignment)(resources.GetObject("lblType.TextAlign")));
																								this.lblType.Visible = ((bool)(resources.GetObject("lblType.Visible")));
																								// 
																								// cboType
																								// 
																								this.cboType.AccessibleDescription = resources.GetString("cboType.AccessibleDescription");
																								this.cboType.AccessibleName = resources.GetString("cboType.AccessibleName");
																								this.cboType.Anchor = ((System.Windows.Forms.AnchorStyles)(resources.GetObject("cboType.Anchor")));
																								this.cboType.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("cboType.BackgroundImage")));
																								this.cboType.Dock = ((System.Windows.Forms.DockStyle)(resources.GetObject("cboType.Dock")));
																								this.cboType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
																								this.cboType.Enabled = ((bool)(resources.GetObject("cboType.Enabled")));
																								this.cboType.Font = ((System.Drawing.Font)(resources.GetObject("cboType.Font")));
																								this.cboType.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("cboType.ImeMode")));
																								this.cboType.IntegralHeight = ((bool)(resources.GetObject("cboType.IntegralHeight")));
																								this.cboType.ItemHeight = ((int)(resources.GetObject("cboType.ItemHeight")));
																								this.cboType.Location = ((System.Drawing.Point)(resources.GetObject("cboType.Location")));
																								this.cboType.MaxDropDownItems = ((int)(resources.GetObject("cboType.MaxDropDownItems")));
																								this.cboType.MaxLength = ((int)(resources.GetObject("cboType.MaxLength")));
																								this.cboType.Name = "cboType";
																								this.cboType.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("cboType.RightToLeft")));
																								this.cboType.Size = ((System.Drawing.Size)(resources.GetObject("cboType.Size")));
																								this.cboType.TabIndex = ((int)(resources.GetObject("cboType.TabIndex")));
																								this.cboType.Text = resources.GetString("cboType.Text");
																								this.cboType.Visible = ((bool)(resources.GetObject("cboType.Visible")));
																								this.cboType.SelectedIndexChanged += new System.EventHandler(this.cboType_SelectedIndexChanged);
																								// 
																								// dgrdData
																								// 
																								this.dgrdData.AccessibleDescription = resources.GetString("dgrdData.AccessibleDescription");
																								this.dgrdData.AccessibleName = resources.GetString("dgrdData.AccessibleName");
																								this.dgrdData.AllowAddNew = ((bool)(resources.GetObject("dgrdData.AllowAddNew")));
																								this.dgrdData.AllowArrows = ((bool)(resources.GetObject("dgrdData.AllowArrows")));
																								this.dgrdData.AllowColMove = ((bool)(resources.GetObject("dgrdData.AllowColMove")));
																								this.dgrdData.AllowColSelect = ((bool)(resources.GetObject("dgrdData.AllowColSelect")));
																								this.dgrdData.AllowDelete = ((bool)(resources.GetObject("dgrdData.AllowDelete")));
																								this.dgrdData.AllowDrag = ((bool)(resources.GetObject("dgrdData.AllowDrag")));
																								this.dgrdData.AllowFilter = ((bool)(resources.GetObject("dgrdData.AllowFilter")));
																								this.dgrdData.AllowHorizontalSplit = ((bool)(resources.GetObject("dgrdData.AllowHorizontalSplit")));
																								this.dgrdData.AllowRowSelect = ((bool)(resources.GetObject("dgrdData.AllowRowSelect")));
																								this.dgrdData.AllowSort = ((bool)(resources.GetObject("dgrdData.AllowSort")));
																								this.dgrdData.AllowUpdate = ((bool)(resources.GetObject("dgrdData.AllowUpdate")));
																								this.dgrdData.AllowUpdateOnBlur = ((bool)(resources.GetObject("dgrdData.AllowUpdateOnBlur")));
																								this.dgrdData.AllowVerticalSplit = ((bool)(resources.GetObject("dgrdData.AllowVerticalSplit")));
																								this.dgrdData.AlternatingRows = ((bool)(resources.GetObject("dgrdData.AlternatingRows")));
																								this.dgrdData.Anchor = ((System.Windows.Forms.AnchorStyles)(resources.GetObject("dgrdData.Anchor")));
																								this.dgrdData.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("dgrdData.BackgroundImage")));
																								this.dgrdData.BorderStyle = ((System.Windows.Forms.BorderStyle)(resources.GetObject("dgrdData.BorderStyle")));
																								this.dgrdData.Caption = resources.GetString("dgrdData.Caption");
																								this.dgrdData.CaptionHeight = ((int)(resources.GetObject("dgrdData.CaptionHeight")));
																								this.dgrdData.CellTipsDelay = ((int)(resources.GetObject("dgrdData.CellTipsDelay")));
																								this.dgrdData.CellTipsWidth = ((int)(resources.GetObject("dgrdData.CellTipsWidth")));
																								this.dgrdData.ChildGrid = ((C1.Win.C1TrueDBGrid.C1TrueDBGrid)(resources.GetObject("dgrdData.ChildGrid")));
																								this.dgrdData.CollapseColor = ((System.Drawing.Color)(resources.GetObject("dgrdData.CollapseColor")));
																								this.dgrdData.ColumnFooters = ((bool)(resources.GetObject("dgrdData.ColumnFooters")));
																								this.dgrdData.ColumnHeaders = ((bool)(resources.GetObject("dgrdData.ColumnHeaders")));
																								this.dgrdData.DefColWidth = ((int)(resources.GetObject("dgrdData.DefColWidth")));
																								this.dgrdData.Dock = ((System.Windows.Forms.DockStyle)(resources.GetObject("dgrdData.Dock")));
																								this.dgrdData.EditDropDown = ((bool)(resources.GetObject("dgrdData.EditDropDown")));
																								this.dgrdData.EmptyRows = ((bool)(resources.GetObject("dgrdData.EmptyRows")));
																								this.dgrdData.Enabled = ((bool)(resources.GetObject("dgrdData.Enabled")));
																								this.dgrdData.ExpandColor = ((System.Drawing.Color)(resources.GetObject("dgrdData.ExpandColor")));
																								this.dgrdData.ExposeCellMode = ((C1.Win.C1TrueDBGrid.ExposeCellModeEnum)(resources.GetObject("dgrdData.ExposeCellMode")));
																								this.dgrdData.ExtendRightColumn = ((bool)(resources.GetObject("dgrdData.ExtendRightColumn")));
																								this.dgrdData.FetchRowStyles = ((bool)(resources.GetObject("dgrdData.FetchRowStyles")));
																								this.dgrdData.FilterBar = ((bool)(resources.GetObject("dgrdData.FilterBar")));
																								this.dgrdData.FlatStyle = ((C1.Win.C1TrueDBGrid.FlatModeEnum)(resources.GetObject("dgrdData.FlatStyle")));
																								this.dgrdData.Font = ((System.Drawing.Font)(resources.GetObject("dgrdData.Font")));
																								this.dgrdData.GroupByAreaVisible = ((bool)(resources.GetObject("dgrdData.GroupByAreaVisible")));
																								this.dgrdData.GroupByCaption = resources.GetString("dgrdData.GroupByCaption");
																								this.dgrdData.Images.Add(((System.Drawing.Image)(resources.GetObject("resource"))));
																								this.dgrdData.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("dgrdData.ImeMode")));
																								this.dgrdData.LinesPerRow = ((int)(resources.GetObject("dgrdData.LinesPerRow")));
																								this.dgrdData.Location = ((System.Drawing.Point)(resources.GetObject("dgrdData.Location")));
																								this.dgrdData.MarqueeStyle = C1.Win.C1TrueDBGrid.MarqueeEnum.DottedCellBorder;
																								this.dgrdData.Name = "dgrdData";
																								this.dgrdData.PictureAddnewRow = ((System.Drawing.Image)(resources.GetObject("dgrdData.PictureAddnewRow")));
																								this.dgrdData.PictureCurrentRow = ((System.Drawing.Image)(resources.GetObject("dgrdData.PictureCurrentRow")));
																								this.dgrdData.PictureFilterBar = ((System.Drawing.Image)(resources.GetObject("dgrdData.PictureFilterBar")));
																								this.dgrdData.PictureFooterRow = ((System.Drawing.Image)(resources.GetObject("dgrdData.PictureFooterRow")));
																								this.dgrdData.PictureHeaderRow = ((System.Drawing.Image)(resources.GetObject("dgrdData.PictureHeaderRow")));
																								this.dgrdData.PictureModifiedRow = ((System.Drawing.Image)(resources.GetObject("dgrdData.PictureModifiedRow")));
																								this.dgrdData.PictureStandardRow = ((System.Drawing.Image)(resources.GetObject("dgrdData.PictureStandardRow")));
																								this.dgrdData.PreviewInfo.AllowSizing = ((bool)(resources.GetObject("dgrdData.PreviewInfo.AllowSizing")));
																								this.dgrdData.PreviewInfo.Caption = resources.GetString("dgrdData.PreviewInfo.Caption");
																								this.dgrdData.PreviewInfo.Location = ((System.Drawing.Point)(resources.GetObject("dgrdData.PreviewInfo.Location")));
																								this.dgrdData.PreviewInfo.Size = ((System.Drawing.Size)(resources.GetObject("dgrdData.PreviewInfo.Size")));
																								this.dgrdData.PreviewInfo.ToolBars = ((bool)(resources.GetObject("dgrdData.PreviewInfo.ToolBars")));
																								this.dgrdData.PreviewInfo.UIStrings.Content = ((string[])(resources.GetObject("dgrdData.PreviewInfo.UIStrings.Content")));
																								this.dgrdData.PreviewInfo.ZoomFactor = ((System.Double)(resources.GetObject("dgrdData.PreviewInfo.ZoomFactor")));
																								this.dgrdData.PrintInfo.MaxRowHeight = ((int)(resources.GetObject("dgrdData.PrintInfo.MaxRowHeight")));
																								this.dgrdData.PrintInfo.OwnerDrawPageFooter = ((bool)(resources.GetObject("dgrdData.PrintInfo.OwnerDrawPageFooter")));
																								this.dgrdData.PrintInfo.OwnerDrawPageHeader = ((bool)(resources.GetObject("dgrdData.PrintInfo.OwnerDrawPageHeader")));
																								this.dgrdData.PrintInfo.PageFooter = resources.GetString("dgrdData.PrintInfo.PageFooter");
																								this.dgrdData.PrintInfo.PageFooterHeight = ((int)(resources.GetObject("dgrdData.PrintInfo.PageFooterHeight")));
																								this.dgrdData.PrintInfo.PageHeader = resources.GetString("dgrdData.PrintInfo.PageHeader");
																								this.dgrdData.PrintInfo.PageHeaderHeight = ((int)(resources.GetObject("dgrdData.PrintInfo.PageHeaderHeight")));
																								this.dgrdData.PrintInfo.PrintHorizontalSplits = ((bool)(resources.GetObject("dgrdData.PrintInfo.PrintHorizontalSplits")));
																								this.dgrdData.PrintInfo.ProgressCaption = resources.GetString("dgrdData.PrintInfo.ProgressCaption");
																								this.dgrdData.PrintInfo.RepeatColumnFooters = ((bool)(resources.GetObject("dgrdData.PrintInfo.RepeatColumnFooters")));
																								this.dgrdData.PrintInfo.RepeatColumnHeaders = ((bool)(resources.GetObject("dgrdData.PrintInfo.RepeatColumnHeaders")));
																								this.dgrdData.PrintInfo.RepeatGridHeader = ((bool)(resources.GetObject("dgrdData.PrintInfo.RepeatGridHeader")));
																								this.dgrdData.PrintInfo.RepeatSplitHeaders = ((bool)(resources.GetObject("dgrdData.PrintInfo.RepeatSplitHeaders")));
																								this.dgrdData.PrintInfo.ShowOptionsDialog = ((bool)(resources.GetObject("dgrdData.PrintInfo.ShowOptionsDialog")));
																								this.dgrdData.PrintInfo.ShowProgressForm = ((bool)(resources.GetObject("dgrdData.PrintInfo.ShowProgressForm")));
																								this.dgrdData.PrintInfo.ShowSelection = ((bool)(resources.GetObject("dgrdData.PrintInfo.ShowSelection")));
																								this.dgrdData.PrintInfo.UseGridColors = ((bool)(resources.GetObject("dgrdData.PrintInfo.UseGridColors")));
																								this.dgrdData.RecordSelectors = ((bool)(resources.GetObject("dgrdData.RecordSelectors")));
																								this.dgrdData.RecordSelectorWidth = ((int)(resources.GetObject("dgrdData.RecordSelectorWidth")));
																								this.dgrdData.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("dgrdData.RightToLeft")));
																								this.dgrdData.RowDivider.Color = ((System.Drawing.Color)(resources.GetObject("resource.Color")));
																								this.dgrdData.RowDivider.Style = ((C1.Win.C1TrueDBGrid.LineStyleEnum)(resources.GetObject("resource.Style")));
																								this.dgrdData.RowHeight = ((int)(resources.GetObject("dgrdData.RowHeight")));
																								this.dgrdData.RowSubDividerColor = ((System.Drawing.Color)(resources.GetObject("dgrdData.RowSubDividerColor")));
																								this.dgrdData.ScrollTips = ((bool)(resources.GetObject("dgrdData.ScrollTips")));
																								this.dgrdData.ScrollTrack = ((bool)(resources.GetObject("dgrdData.ScrollTrack")));
																								this.dgrdData.Size = ((System.Drawing.Size)(resources.GetObject("dgrdData.Size")));
																								this.dgrdData.SpringMode = ((bool)(resources.GetObject("dgrdData.SpringMode")));
																								this.dgrdData.TabAcrossSplits = ((bool)(resources.GetObject("dgrdData.TabAcrossSplits")));
																								this.dgrdData.TabIndex = ((int)(resources.GetObject("dgrdData.TabIndex")));
																								this.dgrdData.Text = resources.GetString("dgrdData.Text");
																								this.dgrdData.ViewCaptionWidth = ((int)(resources.GetObject("dgrdData.ViewCaptionWidth")));
																								this.dgrdData.ViewColumnWidth = ((int)(resources.GetObject("dgrdData.ViewColumnWidth")));
																								this.dgrdData.Visible = ((bool)(resources.GetObject("dgrdData.Visible")));
																								this.dgrdData.WrapCellPointer = ((bool)(resources.GetObject("dgrdData.WrapCellPointer")));
																								this.dgrdData.PropBag = resources.GetString("dgrdData.PropBag");
																								// 
																								// chkSelectAll
																								// 
																								this.chkSelectAll.AccessibleDescription = resources.GetString("chkSelectAll.AccessibleDescription");
																								this.chkSelectAll.AccessibleName = resources.GetString("chkSelectAll.AccessibleName");
																								this.chkSelectAll.Anchor = ((System.Windows.Forms.AnchorStyles)(resources.GetObject("chkSelectAll.Anchor")));
																								this.chkSelectAll.Appearance = ((System.Windows.Forms.Appearance)(resources.GetObject("chkSelectAll.Appearance")));
																								this.chkSelectAll.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("chkSelectAll.BackgroundImage")));
																								this.chkSelectAll.CheckAlign = ((System.Drawing.ContentAlignment)(resources.GetObject("chkSelectAll.CheckAlign")));
																								this.chkSelectAll.Dock = ((System.Windows.Forms.DockStyle)(resources.GetObject("chkSelectAll.Dock")));
																								this.chkSelectAll.Enabled = ((bool)(resources.GetObject("chkSelectAll.Enabled")));
																								this.chkSelectAll.FlatStyle = ((System.Windows.Forms.FlatStyle)(resources.GetObject("chkSelectAll.FlatStyle")));
																								this.chkSelectAll.Font = ((System.Drawing.Font)(resources.GetObject("chkSelectAll.Font")));
																								this.chkSelectAll.Image = ((System.Drawing.Image)(resources.GetObject("chkSelectAll.Image")));
																								this.chkSelectAll.ImageAlign = ((System.Drawing.ContentAlignment)(resources.GetObject("chkSelectAll.ImageAlign")));
																								this.chkSelectAll.ImageIndex = ((int)(resources.GetObject("chkSelectAll.ImageIndex")));
																								this.chkSelectAll.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("chkSelectAll.ImeMode")));
																								this.chkSelectAll.Location = ((System.Drawing.Point)(resources.GetObject("chkSelectAll.Location")));
																								this.chkSelectAll.Name = "chkSelectAll";
																								this.chkSelectAll.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("chkSelectAll.RightToLeft")));
																								this.chkSelectAll.Size = ((System.Drawing.Size)(resources.GetObject("chkSelectAll.Size")));
																								this.chkSelectAll.TabIndex = ((int)(resources.GetObject("chkSelectAll.TabIndex")));
																								this.chkSelectAll.Text = resources.GetString("chkSelectAll.Text");
																								this.chkSelectAll.TextAlign = ((System.Drawing.ContentAlignment)(resources.GetObject("chkSelectAll.TextAlign")));
																								this.chkSelectAll.Visible = ((bool)(resources.GetObject("chkSelectAll.Visible")));
																								this.chkSelectAll.CheckedChanged += new System.EventHandler(this.chkSelectAll_CheckedChanged);
																								// 
																								// RightByRecord
																								// 
																								this.AccessibleDescription = resources.GetString("$this.AccessibleDescription");
																								this.AccessibleName = resources.GetString("$this.AccessibleName");
																								this.AutoScaleBaseSize = ((System.Drawing.Size)(resources.GetObject("$this.AutoScaleBaseSize")));
																								this.AutoScroll = ((bool)(resources.GetObject("$this.AutoScroll")));
																								this.AutoScrollMargin = ((System.Drawing.Size)(resources.GetObject("$this.AutoScrollMargin")));
																								this.AutoScrollMinSize = ((System.Drawing.Size)(resources.GetObject("$this.AutoScrollMinSize")));
																								this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
																								this.CancelButton = this.btnClose;
																								this.ClientSize = ((System.Drawing.Size)(resources.GetObject("$this.ClientSize")));
																								this.Controls.Add(this.chkSelectAll);
																								this.Controls.Add(this.dgrdData);
																								this.Controls.Add(this.lblType);
																								this.Controls.Add(this.cboType);
																								this.Controls.Add(this.lblRole);
																								this.Controls.Add(this.cboRoles);
																								this.Controls.Add(this.btnClose);
																								this.Controls.Add(this.btnHelp);
																								this.Controls.Add(this.btnSave);
																								this.Enabled = ((bool)(resources.GetObject("$this.Enabled")));
																								this.Font = ((System.Drawing.Font)(resources.GetObject("$this.Font")));
																								this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
																								this.ImeMode = ((System.Windows.Forms.ImeMode)(resources.GetObject("$this.ImeMode")));
																								this.Location = ((System.Drawing.Point)(resources.GetObject("$this.Location")));
																								this.MaximumSize = ((System.Drawing.Size)(resources.GetObject("$this.MaximumSize")));
																								this.MinimumSize = ((System.Drawing.Size)(resources.GetObject("$this.MinimumSize")));
																								this.Name = "RightByRecord";
																								this.RightToLeft = ((System.Windows.Forms.RightToLeft)(resources.GetObject("$this.RightToLeft")));
																								this.StartPosition = ((System.Windows.Forms.FormStartPosition)(resources.GetObject("$this.StartPosition")));
																								this.Text = resources.GetString("$this.Text");
																								this.Closing += new System.ComponentModel.CancelEventHandler(this.RightByRecord_Closing);
																								this.Load += new System.EventHandler(this.RightByRecord_Load);
																								((System.ComponentModel.ISupportInitialize)(this.dgrdData)).EndInit();
						this.ResumeLayout(false);

		}
		#endregion
		/// <summary>
		/// RightByRecord_Load
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		/// <Author>Trada</Author>
		/// <date>Wednesday, Nov 16 2005</date>
		private void RightByRecord_Load(object sender, System.EventArgs e)
		{
			// Code Inserted Automatically

			#region Code Inserted Automatically

			this.Cursor = Cursors.WaitCursor;

			#endregion Code Inserted Automatically

			
			const string METHOD_NAME = THIS + ".RightByRecord_Load()";
			try
			{
				//Set authorization for user
				Security objSecurity = new Security();
				this.Name = THIS;
				if(objSecurity.SetRightForUserOnForm(this, SystemProperty.UserName) == 0)
				{
					this.Close();
					// You don't have the right to view this item
					PCSMessageBox.Show(ErrorCode.MESSAGE_YOU_HAVE_NO_RIGHT_TO_VIEW ,MessageBoxIcon.Warning);
																																			// Code Inserted Automatically
																																			#region Code Inserted Automatically
																																			this.Cursor = Cursors.Default;
					#endregion Code Inserted Automatically

					return;
				}
				//Load Combo box for Role
				RightByRecordBO boRightByRecord = new RightByRecordBO();
				dstRole = boRightByRecord.ListRole();
				cboRoles.DataSource = dstRole.Tables[Sys_RoleTable.TABLE_NAME];
				cboRoles.DisplayMember = Sys_RoleTable.NAME_FLD;
				cboRoles.ValueMember = Sys_RoleTable.ROLEID_FLD;
				
				//Load Combo box for Type
				dstTypes = boRightByRecord.ListType();
				cboType.DataSource = dstTypes.Tables[sys_RecordSecurityParamTable.TABLE_NAME];
				
				strText = sys_RecordSecurityParamTable.MENUNAME_FLD;
				switch (strLangName)
				{
					case Constants.CULTURE_VN:
						strText = sys_RecordSecurityParamTable.MENUNAMEVN_FLD;
						break;
					case Constants.CULTURE_JP:
						strText = sys_RecordSecurityParamTable.MENUNAMEJP_FLD;
						break;
					default:
						strText = sys_RecordSecurityParamTable.MENUNAME_FLD;
						break;
				}
				// Set Text for tree node
				cboType.DisplayMember = strText;
				cboType.ValueMember = sys_RecordSecurityParamTable.SOURCETABLENAME_FLD;
				cboType_SelectedIndexChanged(null,null);
				//Filter Row
				dgrdData.FilterActive = true;
				dgrdData.FilterBar = true;
			}
			catch (PCSException ex)
			{
				// Displays the error message if throwed from PCSException.
				PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
				try
				{
					// Log error message into log file.
					Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
				}
				catch
				{
					// Show message if logger has an error.
					PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
				}
			}
			catch (Exception ex)
			{
				// Displays the error message if throwed from system.
				PCSMessageBox.Show(ErrorCode.OTHER_ERROR, MessageBoxIcon.Error);
				try
				{
					// Log error message into log file.
					Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
				}
				catch
				{
					// Show message if logger has an error.
					PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
				}
			}

			// Code Inserted Automatically

			#region Code Inserted Automatically

			this.Cursor = Cursors.Default;

			#endregion Code Inserted Automatically

			
		}
		/// <summary>
		/// GetDataByTableName
		/// </summary>
		/// <param name="pstrTableName"></param>
		/// <returns></returns>
		/// <author>Trada</author>
		/// <date>Wednesday, Nov 16 2005</date>
		private DataSet GetDataByTableName(string pstrTableName)
		{
			const string METHOD_NAME = THIS + ".GetDataByTableName()";
			try
			{
				DataSet dstFieldList = new DataSet();
				ViewTableBO boViewTable = new ViewTableBO();
				int intTableID = boViewTable.GetTableID(pstrTableName);
				dstFieldList = boViewTable.getFieldList(intTableID);
				string strSQLString = boViewTable.BuildSQLSelect(dstFieldList, pstrTableName, true);
				DataSet dstDataReturn = new DataSet();
				dstDataReturn.Tables.Add((boViewTable.getDataList(strSQLString, pstrTableName)).Tables[0].Copy());
				dstDataReturn.Tables.Add(dstFieldList.Tables[0].Copy());
				
				return dstDataReturn;
			}
			catch (PCSException ex)
			{
				throw new PCSException(ex.mCode, METHOD_NAME, ex);
			}
			catch (Exception ex)
			{
				throw new Exception(ex.Message, ex);
			}
		}
		private void btnClose_Click(object sender, System.EventArgs e)
		{
			// Code Inserted Automatically

			#region Code Inserted Automatically

			this.Cursor = Cursors.WaitCursor;

			#endregion Code Inserted Automatically

			
			this.Close();

			// Code Inserted Automatically

			#region Code Inserted Automatically

			this.Cursor = Cursors.Default;

			#endregion Code Inserted Automatically

			
		}
		/// <summary>
		/// cboType_SelectedIndexChanged
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		/// <author>Trada</author>
		/// <date>Wednesday, Nov 16 2005</date>
		private void cboType_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			const string METHOD_NAME = THIS + ".cboType_SelectedIndexChanged()";
			try
			{
				if (dstData.GetChanges() != null)
				{
					DialogResult confirmDialog = PCSMessageBox.Show(ErrorCode.MESSAGE_QUESTION_STORE_INTO_DATABASE, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
					switch (confirmDialog)
					{
						case DialogResult.Yes:
							//Save before exit
							btnSave_Click(btnSave, new EventArgs());
							if (blnHasError)
							{
								return;
							}
							break;
						case DialogResult.No:
							break;
						case DialogResult.Cancel:
							break;
					}
				}
				if (cboType.ValueMember != string.Empty)
				{
					ViewTableBO objViewTableBO = new ViewTableBO();
					
					strText = sys_RecordSecurityParamTable.MENUNAME_FLD;
					switch (strLangName)
					{
						case Constants.CULTURE_VN:
							strText = sys_RecordSecurityParamTable.MENUNAMEVN_FLD;
							break;
						case Constants.CULTURE_JP:
							strText = sys_RecordSecurityParamTable.MENUNAMEJP_FLD;
							break;
						default:
							strText = sys_RecordSecurityParamTable.MENUNAME_FLD;
							break;
					}
					// Set Text for tree node
					DataRow[] drowTypes = dstTypes.Tables[0].Select(strText + " = '" + cboType.Text + "'");
					//Get table name of security table name
					if (drowTypes.Length != 0)
						strSecurityTableName = (drowTypes[0][sys_RecordSecurityParamTable.SECURITYTABLENAME_FLD]).ToString();
					else
						strSecurityTableName = string.Empty;
					DataSet dstTempDataSet = new DataSet();
					//Get data from ComboBox Type
					dstTempDataSet = GetDataByTableName(cboType.SelectedValue.ToString());
					dstData = new DataSet();
					dstData.Tables.Add(strSecurityTableName);
					dstData.Tables[0].Columns.Add(SELECT, typeof(bool));
					for (int i = 0; i < dstTempDataSet.Tables[0].Columns.Count; i++)
						dstData.Tables[0].Columns.Add(dstTempDataSet.Tables[0].Columns[i].ColumnName, dstTempDataSet.Tables[0].Columns[i].DataType);
					foreach(DataRow drow in dstTempDataSet.Tables[0].Rows)
					{
						DataRow drowData = dstData.Tables[0].NewRow(); 
						foreach (DataColumn dcol in dstTempDataSet.Tables[0].Columns)
							drowData[dcol.ColumnName] = drow[dcol.ColumnName];
						dstData.Tables[0].Rows.Add(drowData);
					}
					foreach(DataRow drow in dstData.Tables[0].Rows)
						drow[SELECT] = true;
					//Get data by cboRole
					if((cboRoles.SelectedIndex != -1) && (cboType.SelectedIndex != -1))
					{
						
						RightByRecordBO boRightByRecord = new RightByRecordBO();
						dstSecurityTable = boRightByRecord.GetRightByRecord(int.Parse(cboRoles.SelectedValue.ToString()), strSecurityTableName, cboType.SelectedValue.ToString());
					}
					CommonBO boCommon = new CommonBO();
					//Get primary key column of security table name
					strPKColumnName = boCommon.GetPKColumnName(strSecurityTableName);
					if (strPKColumnName == string.Empty)
						PCSMessageBox.Show(ErrorCode.ERROR_DB, MessageBoxIcon.Error);
					//Get foreign key column of security table name
					strFKColumnName = boCommon.GetFKColumnName(cboType.SelectedValue.ToString(), strSecurityTableName);
					if (strFKColumnName == string.Empty)
						PCSMessageBox.Show(ErrorCode.ERROR_DB, MessageBoxIcon.Error);
					foreach (DataRow drowSecurityTable in dstSecurityTable.Tables[0].Rows)
					{
						foreach (DataRow drowData in dstData.Tables[0].Rows)
						{
							if (drowData[strFKColumnName].ToString() == drowSecurityTable[strFKColumnName].ToString())
								drowData[SELECT] = false;
						}
					}

					//Bind Data to Grid
					dgrdData.DataSource = dstData.Tables[0];
					for (int i = 0; i < dgrdData.Splits[0].DisplayColumns.Count; i++)
					{
						dgrdData.Splits[0].DisplayColumns[i].Locked = true;
						dgrdData.Splits[0].DisplayColumns[i].Style.BackColor = this.BackColor;
					}
					dgrdData.Splits[0].DisplayColumns[SELECT].HeadingStyle.HorizontalAlignment = AlignHorzEnum.Center;
					dgrdData.Splits[0].DisplayColumns[SELECT].Style.HorizontalAlignment =  AlignHorzEnum.Center;
					dgrdData.Splits[0].DisplayColumns[SELECT].Locked = false;
					dgrdData.Splits[0].DisplayColumns[SELECT].Style.BackColor = Color.White;
					//format the grid
					foreach (DataColumn dcolData in dstData.Tables[0].Columns)
					{
						// if data type is decimal then display only 2 digits 
						if (dcolData.DataType == typeof(decimal))
							dgrdData.Columns[dcolData.ColumnName].NumberFormat = Constants.CELL_NUMBER_FORMAT;
						else if (dcolData.DataType == typeof(bool))
						{
							dgrdData.Columns[dcolData.ColumnName].ValueItems.Presentation = PresentationEnum.CheckBox;
							dgrdData.Columns[dcolData.ColumnName].DefaultValue = false.ToString();
							for (int a = 0; a < dstData.Tables[0].Rows.Count; a++)
								if (dstData.Tables[0].Rows[a][dcolData.ColumnName] == DBNull.Value)
									dstData.Tables[0].Rows[a][dcolData.ColumnName] = false;
					
						}
						else if (dcolData.DataType == typeof(DateTime))
						{
							dgrdData.Columns[dcolData.ColumnName].Tag = Constants.DATETIME_TYPE;
							dgrdData.Columns[dcolData.ColumnName].NumberFormat = Constants.DATETIME_FORMAT;
						}
					}
					
					//Set Caption/Width
					//Get the field length for this table from table
					int intFormWidth = 0;
					DataSet dstFieldList = new DataSet();
					string strTableName = cboType.SelectedValue.ToString();
					int intTableID = objViewTableBO.GetTableID(strTableName);
					dstFieldList = objViewTableBO.getFieldList(intTableID);
					DataRow drFieldLength = objViewTableBO.GetFieldLength(dstFieldList, strTableName);

					//loop in the Field List, for each field set its corresponding column in the grid to its properties
					foreach (DataRow drRow in dstFieldList.Tables[0].Rows)
					{
						//get the Field Name
						string strFieldName = ((string) drRow[sys_TableFieldTable.FIELDNAME_FLD]).Trim();

						//Set the True DBGrid , column caption 
						//Select language here 
						
						#region Fix CanhNv
						//dgrdData.Columns[strFieldName].Caption = drRow[sys_TableFieldTable.CAPTION_FLD].ToString();
						strText = drRow[sys_TableFieldTable.CAPTION_FLD].ToString().Trim();
						switch (strLangName)
						{
							case Constants.CULTURE_VN:
								strText = drRow[sys_TableFieldTable.CAPTIONVN_FLD].ToString().Trim();
								break;
							case Constants.CULTURE_JP:
								strText = drRow[sys_TableFieldTable.CAPTIONJP_FLD].ToString().Trim();
								break;
							default:
								strText = drRow[sys_TableFieldTable.CAPTION_FLD].ToString().Trim();
								break;
						}
						dgrdData.Columns[strFieldName].Caption = strText;
						#endregion

						//set the data width for this column
						dgrdData.Columns[strFieldName].DataWidth = int.Parse(drFieldLength[strFieldName].ToString());

						//Sort direction
						int intSortType;
						try
						{
							intSortType = int.Parse(drRow[sys_TableFieldTable.SORTTYPE_FLD].ToString());
						}
						catch 
						{
							intSortType = 0;
						}

						string strSortField = dstData.Tables[0].DefaultView.Sort;
						switch (intSortType)
						{
							case PCSSortType.NONE:
						
								dgrdData.Columns[strFieldName].SortDirection = SortDirEnum.None;
								break;
							case PCSSortType.ASCENDING:
								if (strSortField != String.Empty) 
									strSortField += "," + strFieldName;
								else
									strSortField += strFieldName;
								dgrdData.Columns[strFieldName].SortDirection = SortDirEnum.Ascending;
								break;
							case PCSSortType.DESCENDING:
								dgrdData.Columns[strFieldName].SortDirection = SortDirEnum.Descending;
								if (strSortField != String.Empty) 
									strSortField += "," + strFieldName + " DESC";
								else
									strSortField += strFieldName + " DESC";
								break;
						}
						dstData.Tables[0].DefaultView.Sort = strSortField;

						//set Column Width
						dgrdData.Splits[0].DisplayColumns[strFieldName].Width = int.Parse(drRow[sys_TableFieldTable.WIDTH_FLD].ToString());

						intFormWidth += int.Parse(drRow[sys_TableFieldTable.WIDTH_FLD].ToString());

						if (int.Parse(drRow[sys_TableFieldTable.WIDTH_FLD].ToString()) <= INVISIBLE_COLUMN_WIDTH)
						{
							dgrdData.Splits[0].DisplayColumns[strFieldName].MinWidth = 0;		
							dgrdData.Splits[0].DisplayColumns[strFieldName].Visible = false;
							dgrdData.Splits[0].DisplayColumns[strFieldName].Locked = true;
							dgrdData.Splits[0].DisplayColumns[strFieldName].AllowSizing = false;
							
						}
						//Set the alignment for a column
						int intAlign;
						try
						{
							intAlign = int.Parse(drRow[sys_TableFieldTable.ALIGN_FLD].ToString());
						}
						catch 
						{
							intAlign = 0;
						}
						switch (intAlign)
						{
							case PCSAligmentType.LEFT:
								dgrdData.Splits[0].DisplayColumns[strFieldName].Style.HorizontalAlignment = AlignHorzEnum.Near;
								break;
							case PCSAligmentType.CENTER:
								dgrdData.Splits[0].DisplayColumns[strFieldName].Style.HorizontalAlignment = AlignHorzEnum.Center;
								break;
							case PCSAligmentType.RIGHT:
								dgrdData.Splits[0].DisplayColumns[strFieldName].Style.HorizontalAlignment = AlignHorzEnum.Far;
								break;
						}
						//change the Character Case
						int nCase;
						try 
						{
							nCase = int.Parse(drRow[sys_TableFieldTable.CHARACTERCASE_FLD].ToString());
						}
						catch
						{
							nCase = 0;
						}
						if (nCase != 0)
						{
							dgrdData.Columns[strFieldName].NumberFormat = FORMAT_TEXT;
							dgrdData.Columns[strFieldName].Tag = nCase;
						}
						
						//For a column that gets its value from another table. 
						//We will define this column to be a button
						//When a user clicks at this button it will display another form (another instance of this form)
						if (drRow[sys_TableFieldTable.FROMTABLE_FLD] != null && drRow[sys_TableFieldTable.FROMTABLE_FLD].ToString().Trim() != String.Empty)
						{
							//Invisible the original column 
							dgrdData.Splits[0].DisplayColumns[strFieldName].Visible = false;

							//change this filter column to button enable
							string strFilterFieldName1 = strFieldName + Constants.VIEW_TABLE_FILTER_SEPARATOR + drRow[sys_TableFieldTable.FILTERFIELD1_FLD].ToString().Trim();

							//Create a string array to store temporay value for this column, so that later we can 
							//access this value to understand what we have to do with this column
							string[] strArrayValue1 = new string[6];
							strArrayValue1[0] = drRow[sys_TableFieldTable.FROMTABLE_FLD].ToString().Trim(); //From Table Name
							strArrayValue1[1] = drRow[sys_TableFieldTable.FROMFIELD_FLD].ToString().Trim(); //Return value column
							strArrayValue1[2] = drRow[sys_TableFieldTable.FILTERFIELD1_FLD].ToString().Trim(); //Display value column
							if (drRow[sys_TableFieldTable.FILTERFIELD2_FLD] != null && drRow[sys_TableFieldTable.FILTERFIELD2_FLD].ToString().Trim() != String.Empty)
								strArrayValue1[3] = drRow[sys_TableFieldTable.FILTERFIELD2_FLD].ToString().Trim(); //Display value column
							else
								strArrayValue1[3] = String.Empty; //Display value column
							strArrayValue1[4] = strFieldName; //The column name of this column
							strArrayValue1[5] = drRow[sys_TableFieldTable.FILTERFIELD1_FLD].ToString().Trim(); //the original filter column name
							#region Fix CanhNv
							//dgrdData.Columns[strFilterFieldName1].Caption = drRow[sys_TableFieldTable.FIELD1CAPTIONEN_FLD].ToString().Trim();
							strLangName = CultureInfo.CurrentUICulture.Name;
							strText = drRow[sys_TableFieldTable.FIELD1CAPTIONEN_FLD].ToString().Trim();
							switch (strLangName)
							{
								case Constants.CULTURE_VN:
									strText = drRow[sys_TableFieldTable.FIELD1CAPTIONVN_FLD].ToString().Trim();
									break;
								case Constants.CULTURE_JP:
									strText = drRow[sys_TableFieldTable.FIELD1CAPTIONJP_FLD].ToString().Trim();
									break;
								default:
									strText = drRow[sys_TableFieldTable.FIELD1CAPTIONEN_FLD].ToString().Trim();
									break;
							}
							dgrdData.Columns[strFilterFieldName1].Caption = strText;
							#endregion
							//Get the TableID, TableName, Return Field
							dgrdData.Splits[0].DisplayColumns[strFilterFieldName1].DataColumn.Tag = strArrayValue1;

							//if there is another filter column , we also have to set the same as the previous column is
							if (drRow[sys_TableFieldTable.FILTERFIELD2_FLD] != null && drRow[sys_TableFieldTable.FILTERFIELD2_FLD].ToString().Trim() != String.Empty)
							{
								//change this filter column to button enable
								string strFilterFieldName2 = strFieldName + Constants.VIEW_TABLE_FILTER_SEPARATOR + drRow[sys_TableFieldTable.FILTERFIELD2_FLD].ToString().Trim();
								
								#region Fix CanhNv
								//dgrdData.Columns[strFilterFieldName2].Caption = drRow[sys_TableFieldTable.CAPTION_FLD].ToString().Trim();
								//string strLangName = CultureInfo.CurrentUICulture.Name;
								strText = drRow[sys_TableFieldTable.CAPTION_FLD].ToString().Trim();
								switch (strLangName)
								{
									case Constants.CULTURE_VN:
										strText = drRow[sys_TableFieldTable.CAPTIONVN_FLD].ToString().Trim();
										break;
									case Constants.CULTURE_JP:
										strText = drRow[sys_TableFieldTable.CAPTIONJP_FLD].ToString().Trim();
										break;
									default:
										strText = drRow[sys_TableFieldTable.CAPTION_FLD].ToString().Trim();
										break;
								}
								dgrdData.Columns[strFilterFieldName2].Caption = strText;
								#endregion
								dgrdData.Splits[0].DisplayColumns[strFilterFieldName2].Button = true;

								string[] strArrayValue2 = new string[6];
								strArrayValue2[0] = drRow[sys_TableFieldTable.FROMTABLE_FLD].ToString().Trim(); //From Table Name
								strArrayValue2[1] = drRow[sys_TableFieldTable.FROMFIELD_FLD].ToString().Trim(); //Return value column
								strArrayValue2[2] = drRow[sys_TableFieldTable.FILTERFIELD1_FLD].ToString().Trim(); //Display value column
								strArrayValue2[3] = drRow[sys_TableFieldTable.FILTERFIELD2_FLD].ToString().Trim(); //Display value column
								strArrayValue2[4] = strFieldName; //The column name of this column
								strArrayValue2[5] = drRow[sys_TableFieldTable.FILTERFIELD2_FLD].ToString().Trim(); //The original filter column name of this column

								//Get the TableID, TableName, Return Field
								dgrdData.Splits[0].DisplayColumns[strFilterFieldName2].DataColumn.Tag = strArrayValue2;
							}
						}



						//Change the caption of the Field that get data from another table
						if (drRow[sys_TableFieldTable.FROMTABLE_FLD] != null && drRow[sys_TableFieldTable.FROMTABLE_FLD].ToString().Trim() != String.Empty)
						{
							//Invisible the original column 
							dgrdData.Splits[0].DisplayColumns[strFieldName].AllowSizing =
								dgrdData.Splits[0].DisplayColumns[strFieldName].Visible = false;
							//change this filter column to button enable
							string strFilterFieldName11 = strFieldName + Constants.VIEW_TABLE_FILTER_SEPARATOR + drRow[sys_TableFieldTable.FILTERFIELD1_FLD].ToString().Trim();
							
							#region //if Display external field 1 column
							dgrdData.Columns[strFilterFieldName11].Caption = drRow[sys_TableFieldTable.FIELD1CAPTIONEN_FLD].ToString().Trim();
							dgrdData.Columns[strFilterFieldName11].NumberFormat = drRow[sys_TableFieldTable.FORMATFIELD1_FLD].ToString().Trim();
							if ((drRow[sys_TableFieldTable.WIDTHFIELD1_FLD] != null)&&(drRow[sys_TableFieldTable.WIDTHFIELD1_FLD] != DBNull.Value))
							{
								dgrdData.Splits[0].DisplayColumns[strFilterFieldName11].Width = int.Parse( drRow[sys_TableFieldTable.WIDTHFIELD1_FLD].ToString());
							}
							#endregion
							
							//if there is another filter column , we also have to set the same as the previous column is
							if (drRow[sys_TableFieldTable.FILTERFIELD2_FLD] != null && drRow[sys_TableFieldTable.FILTERFIELD2_FLD].ToString().Trim() != String.Empty)
							{

								//change this filter column to button enable
								string strFilterFieldName22 = strFieldName + Constants.VIEW_TABLE_FILTER_SEPARATOR + drRow[sys_TableFieldTable.FILTERFIELD2_FLD].ToString().Trim();

								#region Fix CanhNv
								//dgrdData.Columns[strFilterFieldName22].Caption = drRow[sys_TableFieldTable.FIELD2CAPTIONEN_FLD].ToString().Trim();
								strLangName = CultureInfo.CurrentUICulture.Name;
								strText = drRow[sys_TableFieldTable.FIELD1CAPTIONEN_FLD].ToString().Trim();
								switch (strLangName)
								{
									case Constants.CULTURE_VN:
										strText = drRow[sys_TableFieldTable.FIELD2CAPTIONVN_FLD].ToString().Trim();
										break;
									case Constants.CULTURE_JP:
										strText = drRow[sys_TableFieldTable.FIELD2CAPTIONJP_FLD].ToString().Trim();
										break;
									default:
										strText = drRow[sys_TableFieldTable.FIELD2CAPTIONEN_FLD].ToString().Trim();
										break;
								}
								dgrdData.Columns[strFilterFieldName22].Caption = strText;
								#endregion

								if ((drRow[sys_TableFieldTable.WIDTH_FLD] != null)&&(drRow[sys_TableFieldTable.WIDTH_FLD] != DBNull.Value))
								{
									dgrdData.Splits[0].DisplayColumns[strFilterFieldName22].Width = int.Parse(drRow[sys_TableFieldTable.WIDTH_FLD].ToString());
								}
								dgrdData.Columns[strFilterFieldName22].NumberFormat = drRow[sys_TableFieldTable.FORMATFIELD2_FLD].ToString().Trim();
								if(dgrdData.Splits[0].DisplayColumns[strFilterFieldName22].Width <= 1)
								{
									dgrdData.Splits[0].DisplayColumns[strFilterFieldName22].AllowSizing =
										dgrdData.Splits[0].DisplayColumns[strFilterFieldName22].Visible = false;
								}
							}
						}

					}
				}
				dstData.AcceptChanges();
			}
			catch (PCSException ex)
			{
				// Displays the error message if throwed from PCSException.
				PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
				try
				{
					// Log error message into log file.
					Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
				}
				catch
				{
					// Show message if logger has an error.
					PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
				}
			}
			catch (Exception ex)
			{
				// Displays the error message if throwed from system.
				PCSMessageBox.Show(ErrorCode.OTHER_ERROR, MessageBoxIcon.Error);
				try
				{
					// Log error message into log file.
					Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
				}
				catch
				{
					// Show message if logger has an error.
					PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
				}
			}
		}
		public bool CheckHasID(int pintItemID, int pintRoleID)
		{
			DataRow[] arrdowData = dstSecurityTable.Tables[0].Select(strFKColumnName + " = '" + pintItemID.ToString() + "'"
				+ " AND " + sys_RolePartyTable.ROLEID_FLD + " = '" + pintRoleID.ToString() + "'");
			if (arrdowData.Length > 0)
			{
				return true;
			}
			else
				return false;
			
		}
		/// <summary>
		/// ValidateData
		/// </summary>
		/// <returns></returns>
		/// <author>Trada</author>
		/// <date>Thursday, Nov 17 2005</date>
		private bool ValidateData()
		{
			const string METHOD_NAME = THIS + ".ValidateData()";
			try
			{
				//Check mandatory
				if (FormControlComponents.CheckMandatory(cboRoles))
				{
					PCSMessageBox.Show(ErrorCode.MANDATORY_INVALID);
					cboRoles.Focus();
					return false;
				}
				if (FormControlComponents.CheckMandatory(cboType))
				{
					PCSMessageBox.Show(ErrorCode.MANDATORY_INVALID);
					cboType.Focus();
					return false;
				}
			}
			catch (PCSException ex)
			{
				throw new PCSException(ex.mCode, METHOD_NAME, ex);
			}
			catch (Exception ex)
			{
				throw new Exception(ex.Message, ex);
			}
			return true;
		}
		/// <summary>
		/// btnSave_Click
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		/// <author>Trada</author>
		/// <date>Thursday, Nov 17 2005</date>
		private void btnSave_Click(object sender, System.EventArgs e)
		{
			// Code Inserted Automatically

			#region Code Inserted Automatically

			this.Cursor = Cursors.WaitCursor;

			#endregion Code Inserted Automatically

			
			const string METHOD_NAME = THIS + ".btnSave_Click()";
			try
			{
				blnHasError = true;
				if (ValidateData())
				{
					RightByRecordBO boRightByRecord = new RightByRecordBO();
					int intRoleID = int.Parse(cboRoles.SelectedValue.ToString());
					foreach (DataRow drowData in dstData.Tables[0].Rows)
					{
						DataRow drowNewSecurityTableRow = dstSecurityTable.Tables[0].NewRow(); 
						if (drowData[SELECT].ToString() == false.ToString())
						{
							if (!CheckHasID(int.Parse(drowData[strFKColumnName].ToString()), intRoleID))
							{
								//add new row to dstSecurityTable
								drowNewSecurityTableRow[sys_RolePartyTable.ROLEID_FLD] = intRoleID;
								drowNewSecurityTableRow[strFKColumnName] = drowData[strFKColumnName];
								dstSecurityTable.Tables[0].Rows.Add(drowNewSecurityTableRow);
							}
						}
						else
						{
							foreach (DataRow drowSecurityTable in dstSecurityTable.Tables[0].Rows)
							{
								if (drowSecurityTable.RowState != DataRowState.Deleted)
								{
									if (drowData[strFKColumnName].ToString() == drowSecurityTable[strFKColumnName].ToString())
									{
										drowSecurityTable.Delete();
									}
								}
							}
						}
					}
					
					boRightByRecord.UpdateSecurityTable(dstSecurityTable, strSecurityTableName, cboType.SelectedValue.ToString());
					PCSMessageBox.Show(ErrorCode.MESSAGE_AFTER_SAVE_DATA);
					blnHasError = false;
					dstData.AcceptChanges();
					cboType_SelectedIndexChanged(null, null);
				}
			}
			catch (PCSException ex)
			{
				// Displays the error message if throwed from PCSException.
				PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
				try
				{
					// Log error message into log file.
					Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
				}
				catch
				{
					// Show message if logger has an error.
					PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
				}
			}
			catch (Exception ex)
			{
				// Displays the error message if throwed from system.
				PCSMessageBox.Show(ErrorCode.OTHER_ERROR, MessageBoxIcon.Error);
				try
				{
					// Log error message into log file.
					Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
				}
				catch
				{
					// Show message if logger has an error.
					PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
				}
			}

			// Code Inserted Automatically

			#region Code Inserted Automatically

			this.Cursor = Cursors.Default;

			#endregion Code Inserted Automatically

			
		}
		/// <summary>
		/// RightByRecord_Closing
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		/// <author>Trada</author>
		/// <date>Friday, Nov 18 2005</date>
		private void RightByRecord_Closing(object sender, System.ComponentModel.CancelEventArgs e)
		{
			const string METHOD_NAME = THIS + ".RightByRecord_Closing()";
			try
			{
				if (dstData.GetChanges() != null)
				{
					DialogResult confirmDialog = PCSMessageBox.Show(ErrorCode.MESSAGE_QUESTION_STORE_INTO_DATABASE, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
					switch (confirmDialog)
					{
						case DialogResult.Yes:
							//Save before exit
							btnSave_Click(btnSave, new EventArgs());
							if (blnHasError)
							{
								e.Cancel = true;
							}
							break;
						case DialogResult.No:
							break;
						case DialogResult.Cancel:
							e.Cancel = true;
							break;
					}
				}
			}
			catch (PCSException ex)
			{
				PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
				try
				{
					Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
				}
				catch
				{
					PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
				}
			}
			catch (Exception ex)
			{
				PCSMessageBox.Show(ErrorCode.OTHER_ERROR, MessageBoxIcon.Error);
				try
				{
					Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
				}
				catch
				{
					PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
				}
			}
		}
		/// <summary>
		/// chkSelectAll_CheckedChanged
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		/// <author>Trada</author>
		/// <date>Monday, December 12 2005</date>
		private void chkSelectAll_CheckedChanged(object sender, System.EventArgs e)
		{
			const string METHOD_NAME = THIS + ".chkSelectAll_CheckedChanged()";
			try
			{
				if (dgrdData.RowCount != 0)
				{
					for (int i = 0; i < dgrdData.RowCount; i++)
					{
						if (chkSelectAll.Checked)
						{
							dgrdData[i, SELECT] = true;
						}
						else
							dgrdData[i, SELECT] = false;
					}
				}
			}
			catch (PCSException ex)
			{
				PCSMessageBox.Show(ex.mCode, MessageBoxIcon.Error);
				try
				{
					Logger.LogMessage(ex.CauseException, METHOD_NAME, Level.ERROR);
				}
				catch
				{
					PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
				}
			}
			catch (Exception ex)
			{
				PCSMessageBox.Show(ErrorCode.OTHER_ERROR, MessageBoxIcon.Error);
				try
				{
					Logger.LogMessage(ex, METHOD_NAME, Level.ERROR);
				}
				catch
				{
					PCSMessageBox.Show(ErrorCode.LOG_EXCEPTION, MessageBoxIcon.Error);
				}
			}
		}		
	}
}